﻿using SketchUpAPI.NET.Enums;
using SketchUpAPI.NET.SketchUp.Exception;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace SketchUpAPI.NET.Objects
{
    /// <summary>
    /// 地理位置信息
    /// </summary>
    /// <remarks>对 AketchUpAPI 中的 SULocationRef 的包装</remarks>
    public class Location : ObjectBase
    {
        #region API 函数
        /// <summary>
        /// 获取经纬度
        /// </summary>
        /// <param name="location"></param>
        /// <param name="latitude"></param>
        /// <param name="longitude"></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SULocationGetLatLong(IntPtr location, out double latitude, out double longitude);

        /// <summary>
        /// 设置经纬度
        /// </summary>
        /// <param name="location"></param>
        /// <param name="latitude"></param>
        /// <param name="longitude"></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SULocationSetLatLong(IntPtr location, double latitude, double longitude);

        /// <summary>
        /// 设置北极角度
        /// </summary>
        /// <param name="location"></param>
        /// <param name="north_angle"></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SULocationSetNorthAngle(IntPtr location, double north_angle);
        #endregion

        internal Location(IntPtr id) => Id = id;

        /// <summary>
        /// 获取经纬度
        /// </summary>
        /// <param name="latitude">维度 [-90, 90]</param>
        /// <param name="longitude">精度 [-180, 180]</param>
        public void GetLatLong(out double latitude, out double longitude)
        {
            SketchUpExceptionHelper.ThrowSUResult(SULocationGetLatLong(Id, out latitude, out longitude));
        }

        /// <summary>
        /// 设置经纬度
        /// </summary>
        /// <param name="latitude">维度 [-90, 90]</param>
        /// <param name="longitude">精度 [-180, 180]</param>
        public void SetLatLong(double latitude, double longitude)
        {
            SketchUpExceptionHelper.ThrowSUResult(SULocationSetLatLong(Id, latitude, longitude));
        }

        /// <summary>
        /// 设置北极角度
        /// </summary>
        /// <param name="north_angle"></param>
        public void SetNorthAngle(double north_angle)
        {
            SketchUpExceptionHelper.ThrowSUResult(SULocationSetNorthAngle(Id, north_angle));
        }
    }
}